package com.teach;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * <pre>
 * - 
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2021-4-16 10:46:16
 * Version : 1.0
 * Copyright 2021 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 *
 */
public class Demo0202 {

	public static void main(String[] args) {
		System.out.println("430124198101070011:" + hasAdult("430124198101070011"));// true
		System.out.println("430124202101070011:" + hasAdult("430124202101070011"));// false

	}

	/**
	 * - 根据身份证号码判断是否成年
	 * 
	 * @param idcard
	 * @return
	 */
	public static boolean hasAdult(String idcard) {
		if (!idcard.matches("^\\d{17}[\\dX]$")) {
			throw new RuntimeException("18位的身份证号码不正确");
		}
		String ymd = idcard.substring(6, 14);
		System.out.println(ymd);
		DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd");
		LocalDate d = LocalDate.parse(ymd, f);
		d = d.plusYears(18);
		System.out.println(d);
		return d.isBefore(LocalDate.now());

	}
}
